javax.print.attribute.standard.MediaPrintableArea Java Examples

The following examples show how to use javax.print.attribute.standard.MediaPrintableArea. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Win32PrintService.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private boolean isSupportedMediaPrintableArea(MediaPrintableArea mpa) {

        getMediaPrintables(null);
        int units = MediaPrintableArea.INCH;

        if (mediaPrintables != null) {
            for (int i=0; i<mediaPrintables.length; i++) {
                if ((mpa.getX(units) >= mediaPrintables[i].getX(units)) &&
                    (mpa.getY(units) >= mediaPrintables[i].getY(units)) &&
                    (mpa.getX(units) + mpa.getWidth(units) <=
                            mediaPrintables[i].getX(units) +
                            mediaPrintables[i].getWidth(units)) &&
                    (mpa.getY(units) + mpa.getHeight(units) <=
                            mediaPrintables[i].getY(units) +
                            mediaPrintables[i].getHeight(units))) {
                    return true;
                }
            }
        }
        return false;
    }
 
Example #2
Source File: RasterPrinterJob.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page,
        double w, double h) {
    double ix, iw, iy, ih;
        if (w >= 72.0 * 6.0) {
            ix = 72.0;
            iw = w - 2 * 72.0;
        } else {
            ix = w / 6.0;
            iw = w * 0.75;
        }
        if (h >= 72.0 * 6.0) {
            iy = 72.0;
            ih = h - 2 * 72.0;
        } else {
            iy = h / 6.0;
            ih = h * 0.75;
        }

    return new MediaPrintableArea((float) (ix / DPI), (float) (iy / DPI),
            (float) (iw / DPI), (float) (ih / DPI), MediaPrintableArea.INCH);
}
 
Example #3
Source File: UnixPrintService.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private MediaPrintableArea[] getAllPrintableAreas() {

        if (mpas == null) {
            Media[] media = (Media[])getSupportedAttributeValues(Media.class,
                                                                 null, null);
            mpas = new MediaPrintableArea[media.length];
            for (int i=0; i< mpas.length; i++) {
                if (media[i] instanceof MediaSizeName) {
                    MediaSizeName msn = (MediaSizeName)media[i];
                    MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
                    if (mediaSize == null) {
                        mpas[i] = (MediaPrintableArea)
                            getDefaultAttributeValue(MediaPrintableArea.class);
                    } else {
                        mpas[i] = new MediaPrintableArea(0.25f, 0.25f,
                                        mediaSize.getX(MediaSize.INCH)-0.5f,
                                        mediaSize.getY(MediaSize.INCH)-0.5f,
                                        MediaSize.INCH);
                    }
                }
            }
        }
        MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
        System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
        return mpasCopy;
    }
 
Example #4
Source File: UnixPrintService.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private MediaPrintableArea[] getAllPrintableAreas() {

        if (mpas == null) {
            Media[] media = (Media[])getSupportedAttributeValues(Media.class,
                                                                 null, null);
            mpas = new MediaPrintableArea[media.length];
            for (int i=0; i< mpas.length; i++) {
                if (media[i] instanceof MediaSizeName) {
                    MediaSizeName msn = (MediaSizeName)media[i];
                    MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
                    if (mediaSize == null) {
                        mpas[i] = (MediaPrintableArea)
                            getDefaultAttributeValue(MediaPrintableArea.class);
                    } else {
                        mpas[i] = new MediaPrintableArea(0.25f, 0.25f,
                                        mediaSize.getX(MediaSize.INCH)-0.5f,
                                        mediaSize.getY(MediaSize.INCH)-0.5f,
                                        MediaSize.INCH);
                    }
                }
            }
        }
        MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
        System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
        return mpasCopy;
    }
 
Example #5
Source File: RasterPrinterJob.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page,
        double w, double h) {
    double ix, iw, iy, ih;
        if (w >= 72.0 * 6.0) {
            ix = 72.0;
            iw = w - 2 * 72.0;
        } else {
            ix = w / 6.0;
            iw = w * 0.75;
        }
        if (h >= 72.0 * 6.0) {
            iy = 72.0;
            ih = h - 2 * 72.0;
        } else {
            iy = h / 6.0;
            ih = h * 0.75;
        }

    return new MediaPrintableArea((float) (ix / DPI), (float) (iy / DPI),
            (float) (iw / DPI), (float) (ih / DPI), MediaPrintableArea.INCH);
}
 
Example #6
Source File: UnixPrintService.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private MediaPrintableArea[] getAllPrintableAreas() {

        if (mpas == null) {
            Media[] media = (Media[])getSupportedAttributeValues(Media.class,
                                                                 null, null);
            mpas = new MediaPrintableArea[media.length];
            for (int i=0; i< mpas.length; i++) {
                if (media[i] instanceof MediaSizeName) {
                    MediaSizeName msn = (MediaSizeName)media[i];
                    MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
                    if (mediaSize == null) {
                        mpas[i] = (MediaPrintableArea)
                            getDefaultAttributeValue(MediaPrintableArea.class);
                    } else {
                        mpas[i] = new MediaPrintableArea(0.25f, 0.25f,
                                        mediaSize.getX(MediaSize.INCH)-0.5f,
                                        mediaSize.getY(MediaSize.INCH)-0.5f,
                                        MediaSize.INCH);
                    }
                }
            }
        }
        MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
        System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
        return mpasCopy;
    }
 
Example #7
Source File: RasterPrinterJob.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page,
        double w, double h) {
    double ix, iw, iy, ih;
    if (w >= 72.0 * 6.0) {
        ix = 72.0;
        iw = w - 2 * 72.0;
    } else {
        ix = w / 6.0;
        iw = w * 0.75;
    }
    if (h >= 72.0 * 6.0) {
        iy = 72.0;
        ih = h - 2 * 72.0;
    } else {
        iy = h / 6.0;
        ih = h * 0.75;
    }

    return new MediaPrintableArea((float) (ix / DPI), (float) (iy / DPI),
            (float) (iw / DPI), (float) (ih / DPI), MediaPrintableArea.INCH);
}
 
Example #8
Source File: UnixPrintService.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private MediaPrintableArea[] getAllPrintableAreas() {

        if (mpas == null) {
            Media[] media = (Media[])getSupportedAttributeValues(Media.class,
                                                                 null, null);
            mpas = new MediaPrintableArea[media.length];
            for (int i=0; i< mpas.length; i++) {
                if (media[i] instanceof MediaSizeName) {
                    MediaSizeName msn = (MediaSizeName)media[i];
                    MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
                    if (mediaSize == null) {
                        mpas[i] = (MediaPrintableArea)
                            getDefaultAttributeValue(MediaPrintableArea.class);
                    } else {
                        mpas[i] = new MediaPrintableArea(0.25f, 0.25f,
                                        mediaSize.getX(MediaSize.INCH)-0.5f,
                                        mediaSize.getY(MediaSize.INCH)-0.5f,
                                        MediaSize.INCH);
                    }
                }
            }
        }
        MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
        System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
        return mpasCopy;
    }
 
Example #9
Source File: RasterPrinterJob.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page,
        double w, double h) {
    double ix, iw, iy, ih;
        if (w >= 72.0 * 6.0) {
            ix = 72.0;
            iw = w - 2 * 72.0;
        } else {
            ix = w / 6.0;
            iw = w * 0.75;
        }
        if (h >= 72.0 * 6.0) {
            iy = 72.0;
            ih = h - 2 * 72.0;
        } else {
            iy = h / 6.0;
            ih = h * 0.75;
        }

    return new MediaPrintableArea((float) (ix / DPI), (float) (iy / DPI),
            (float) (iw / DPI), (float) (ih / DPI), MediaPrintableArea.INCH);
}
 
Example #10
Source File: UnixPrintService.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private MediaPrintableArea[] getAllPrintableAreas() {

        if (mpas == null) {
            Media[] media = (Media[])getSupportedAttributeValues(Media.class,
                                                                 null, null);
            mpas = new MediaPrintableArea[media.length];
            for (int i=0; i< mpas.length; i++) {
                if (media[i] instanceof MediaSizeName) {
                    MediaSizeName msn = (MediaSizeName)media[i];
                    MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
                    if (mediaSize == null) {
                        mpas[i] = (MediaPrintableArea)
                            getDefaultAttributeValue(MediaPrintableArea.class);
                    } else {
                        mpas[i] = new MediaPrintableArea(0.25f, 0.25f,
                                        mediaSize.getX(MediaSize.INCH)-0.5f,
                                        mediaSize.getY(MediaSize.INCH)-0.5f,
                                        MediaSize.INCH);
                    }
                }
            }
        }
        MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
        System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
        return mpasCopy;
    }
 
Example #11
Source File: UnixPrintService.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private MediaPrintableArea[] getAllPrintableAreas() {

        if (mpas == null) {
            Media[] media = (Media[])getSupportedAttributeValues(Media.class,
                                                                 null, null);
            mpas = new MediaPrintableArea[media.length];
            for (int i=0; i< mpas.length; i++) {
                if (media[i] instanceof MediaSizeName) {
                    MediaSizeName msn = (MediaSizeName)media[i];
                    MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
                    if (mediaSize == null) {
                        mpas[i] = (MediaPrintableArea)
                            getDefaultAttributeValue(MediaPrintableArea.class);
                    } else {
                        mpas[i] = new MediaPrintableArea(0.25f, 0.25f,
                                        mediaSize.getX(MediaSize.INCH)-0.5f,
                                        mediaSize.getY(MediaSize.INCH)-0.5f,
                                        MediaSize.INCH);
                    }
                }
            }
        }
        MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
        System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
        return mpasCopy;
    }
 
Example #12
Source File: UnixPrintService.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private MediaPrintableArea[] getAllPrintableAreas() {

        if (mpas == null) {
            Media[] media = (Media[])getSupportedAttributeValues(Media.class,
                                                                 null, null);
            mpas = new MediaPrintableArea[media.length];
            for (int i=0; i< mpas.length; i++) {
                if (media[i] instanceof MediaSizeName) {
                    MediaSizeName msn = (MediaSizeName)media[i];
                    MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
                    if (mediaSize == null) {
                        mpas[i] = (MediaPrintableArea)
                            getDefaultAttributeValue(MediaPrintableArea.class);
                    } else {
                        mpas[i] = new MediaPrintableArea(0.25f, 0.25f,
                                        mediaSize.getX(MediaSize.INCH)-0.5f,
                                        mediaSize.getY(MediaSize.INCH)-0.5f,
                                        MediaSize.INCH);
                    }
                }
            }
        }
        MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
        System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
        return mpasCopy;
    }
 
Example #13
Source File: UnixPrintService.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private MediaPrintableArea[] getAllPrintableAreas() {

        if (mpas == null) {
            Media[] media = (Media[])getSupportedAttributeValues(Media.class,
                                                                 null, null);
            mpas = new MediaPrintableArea[media.length];
            for (int i=0; i< mpas.length; i++) {
                if (media[i] instanceof MediaSizeName) {
                    MediaSizeName msn = (MediaSizeName)media[i];
                    MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
                    if (mediaSize == null) {
                        mpas[i] = (MediaPrintableArea)
                            getDefaultAttributeValue(MediaPrintableArea.class);
                    } else {
                        mpas[i] = new MediaPrintableArea(0.25f, 0.25f,
                                        mediaSize.getX(MediaSize.INCH)-0.5f,
                                        mediaSize.getY(MediaSize.INCH)-0.5f,
                                        MediaSize.INCH);
                    }
                }
            }
        }
        MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
        System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
        return mpasCopy;
    }
 
Example #14
Source File: RasterPrinterJob.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page,
        double w, double h) {
    double ix, iw, iy, ih;
        if (w >= 72.0 * 6.0) {
            ix = 72.0;
            iw = w - 2 * 72.0;
        } else {
            ix = w / 6.0;
            iw = w * 0.75;
        }
        if (h >= 72.0 * 6.0) {
            iy = 72.0;
            ih = h - 2 * 72.0;
        } else {
            iy = h / 6.0;
            ih = h * 0.75;
        }

    return new MediaPrintableArea((float) (ix / DPI), (float) (iy / DPI),
            (float) (iw / DPI), (float) (ih / DPI), MediaPrintableArea.INCH);
}
 
Example #15
Source File: UnixPrintService.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private MediaPrintableArea[] getAllPrintableAreas() {

        if (mpas == null) {
            Media[] media = (Media[])getSupportedAttributeValues(Media.class,
                                                                 null, null);
            mpas = new MediaPrintableArea[media.length];
            for (int i=0; i< mpas.length; i++) {
                if (media[i] instanceof MediaSizeName) {
                    MediaSizeName msn = (MediaSizeName)media[i];
                    MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
                    if (mediaSize == null) {
                        mpas[i] = (MediaPrintableArea)
                            getDefaultAttributeValue(MediaPrintableArea.class);
                    } else {
                        mpas[i] = new MediaPrintableArea(0.25f, 0.25f,
                                        mediaSize.getX(MediaSize.INCH)-0.5f,
                                        mediaSize.getY(MediaSize.INCH)-0.5f,
                                        MediaSize.INCH);
                    }
                }
            }
        }
        MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
        System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
        return mpasCopy;
    }
 
Example #16
Source File: Java14PrintUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static PageFormat extractPageFormat( final PrintRequestAttributeSet attributeSet ) {
  final Media media = (Media) attributeSet.get( Media.class );
  final MediaPrintableArea printableArea = (MediaPrintableArea) attributeSet.get( MediaPrintableArea.class );
  final OrientationRequested orientationRequested =
      (OrientationRequested) attributeSet.get( OrientationRequested.class );

  final MediaSize mediaSize = lookupMediaSize( media );
  if ( mediaSize == null ) {
    logger.warn( "Unknown media encountered, unable to compute page sizes." );
  }

  final PageFormat pageFormat = new PageFormat();
  pageFormat.setPaper( createPaper( mediaSize, printableArea ) );
  if ( OrientationRequested.PORTRAIT.equals( orientationRequested ) ) {
    pageFormat.setOrientation( PageFormat.PORTRAIT );
  } else if ( OrientationRequested.LANDSCAPE.equals( orientationRequested ) ) {
    pageFormat.setOrientation( PageFormat.LANDSCAPE );
  } else if ( OrientationRequested.REVERSE_LANDSCAPE.equals( orientationRequested ) ) {
    pageFormat.setOrientation( PageFormat.REVERSE_LANDSCAPE );
  } else if ( OrientationRequested.REVERSE_PORTRAIT.equals( orientationRequested ) ) {
    pageFormat.setOrientation( PageFormat.PORTRAIT );
  }
  return pageFormat;
}
 
Example #17
Source File: RasterPrinterJob.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page,
        double w, double h) {
    double ix, iw, iy, ih;
        if (w >= 72.0 * 6.0) {
            ix = 72.0;
            iw = w - 2 * 72.0;
        } else {
            ix = w / 6.0;
            iw = w * 0.75;
        }
        if (h >= 72.0 * 6.0) {
            iy = 72.0;
            ih = h - 2 * 72.0;
        } else {
            iy = h / 6.0;
            ih = h * 0.75;
        }

    return new MediaPrintableArea((float) (ix / DPI), (float) (iy / DPI),
            (float) (iw / DPI), (float) (ih / DPI), MediaPrintableArea.INCH);
}
 
Example #18
Source File: UnixPrintService.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private MediaPrintableArea[] getAllPrintableAreas() {

        if (mpas == null) {
            Media[] media = (Media[])getSupportedAttributeValues(Media.class,
                                                                 null, null);
            mpas = new MediaPrintableArea[media.length];
            for (int i=0; i< mpas.length; i++) {
                if (media[i] instanceof MediaSizeName) {
                    MediaSizeName msn = (MediaSizeName)media[i];
                    MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
                    if (mediaSize == null) {
                        mpas[i] = (MediaPrintableArea)
                            getDefaultAttributeValue(MediaPrintableArea.class);
                    } else {
                        mpas[i] = new MediaPrintableArea(0.25f, 0.25f,
                                        mediaSize.getX(MediaSize.INCH)-0.5f,
                                        mediaSize.getY(MediaSize.INCH)-0.5f,
                                        MediaSize.INCH);
                    }
                }
            }
        }
        MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
        System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
        return mpasCopy;
    }
 
Example #19
Source File: UnixPrintService.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private MediaPrintableArea[] getAllPrintableAreas() {

        if (mpas == null) {
            Media[] media = (Media[])getSupportedAttributeValues(Media.class,
                                                                 null, null);
            mpas = new MediaPrintableArea[media.length];
            for (int i=0; i< mpas.length; i++) {
                if (media[i] instanceof MediaSizeName) {
                    MediaSizeName msn = (MediaSizeName)media[i];
                    MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
                    if (mediaSize == null) {
                        mpas[i] = (MediaPrintableArea)
                            getDefaultAttributeValue(MediaPrintableArea.class);
                    } else {
                        mpas[i] = new MediaPrintableArea(0.25f, 0.25f,
                                        mediaSize.getX(MediaSize.INCH)-0.5f,
                                        mediaSize.getY(MediaSize.INCH)-0.5f,
                                        MediaSize.INCH);
                    }
                }
            }
        }
        MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
        System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
        return mpasCopy;
    }
 
Example #20
Source File: RasterPrinterJob.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page,
        double w, double h) {
    double ix, iw, iy, ih;
        if (w >= 72.0 * 6.0) {
            ix = 72.0;
            iw = w - 2 * 72.0;
        } else {
            ix = w / 6.0;
            iw = w * 0.75;
        }
        if (h >= 72.0 * 6.0) {
            iy = 72.0;
            ih = h - 2 * 72.0;
        } else {
            iy = h / 6.0;
            ih = h * 0.75;
        }

    return new MediaPrintableArea((float) (ix / DPI), (float) (iy / DPI),
            (float) (iw / DPI), (float) (ih / DPI), MediaPrintableArea.INCH);
}
 
Example #21
Source File: RasterPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page,
        double w, double h) {
    double ix, iw, iy, ih;
        if (w >= 72.0 * 6.0) {
            ix = 72.0;
            iw = w - 2 * 72.0;
        } else {
            ix = w / 6.0;
            iw = w * 0.75;
        }
        if (h >= 72.0 * 6.0) {
            iy = 72.0;
            ih = h - 2 * 72.0;
        } else {
            iy = h / 6.0;
            ih = h * 0.75;
        }

    return new MediaPrintableArea((float) (ix / DPI), (float) (iy / DPI),
            (float) (iw / DPI), (float) (ih / DPI), MediaPrintableArea.INCH);
}
 
Example #22
Source File: RasterPrinterJob.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page,
        double w, double h) {
    double ix, iw, iy, ih;
        if (w >= 72.0 * 6.0) {
            ix = 72.0;
            iw = w - 2 * 72.0;
        } else {
            ix = w / 6.0;
            iw = w * 0.75;
        }
        if (h >= 72.0 * 6.0) {
            iy = 72.0;
            ih = h - 2 * 72.0;
        } else {
            iy = h / 6.0;
            ih = h * 0.75;
        }

    return new MediaPrintableArea((float) (ix / DPI), (float) (iy / DPI),
            (float) (iw / DPI), (float) (ih / DPI), MediaPrintableArea.INCH);
}
 
Example #23
Source File: TestPgfmtSetMPA.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    PrinterJob job;

    job = PrinterJob.getPrinterJob();

    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();

    // Here you could see the PageFormat with an empty PrintRequestAttributeSet
    PageFormat pf2 = job.getPageFormat(pras);
    System.out.println((pf2.getImageableX() / 72f) + " "
            + (pf2.getImageableY() / 72f) + " "
            + (pf2.getImageableWidth() / 72f) + " "
            + (pf2.getImageableHeight() / 72f)
    );

    // Set left margin to 2.0
    pras.add(new MediaPrintableArea(2.0f,
            (float)(pf2.getImageableY() / 72f),
            (float) ((pf2.getImageableWidth() / 72f) - 1.0f),
            (float) (pf2.getImageableHeight() / 72f),
            MediaPrintableArea.INCH));

    pf2 = job.getPageFormat(pras);
    System.out.println((pf2.getImageableX() / 72f) + " "
            + (pf2.getImageableY() / 72f) + " "
            + (pf2.getImageableWidth() / 72f) + " "
            + (pf2.getImageableHeight() / 72f)
    );

    // check if returned left margin of imageable area is 2.0 as set earlier
    if (pf2.getImageableX() / 72f != 2.0f) {
        throw new RuntimeException("getPageFormat doesn't apply specified "
                + "MediaPrintableArea attribute");
    }
}
 
Example #24
Source File: PageDialogMarginTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static double getPrintableXFromASet(PrintRequestAttributeSet aset) {
    try {
        return ((MediaPrintableArea) aset.get(
                MediaPrintableArea.class)).getX(MediaPrintableArea.INCH);
    } catch (Exception e) {
        return -1.0;
    }
}
 
Example #25
Source File: CPrinterJob.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page, double w, double h) {
    final float dpi = 72.0f;
    Paper paper = page.getPaper();
    return new MediaPrintableArea(
            (float) (paper.getImageableX() / dpi),
            (float) (paper.getImageableY() / dpi),
            (float) (paper.getImageableWidth() / dpi),
            (float) (paper.getImageableHeight() / dpi),
            MediaPrintableArea.INCH);
}
 
Example #26
Source File: Win32PrintService.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private boolean isSupportedMediaPrintableArea(MediaPrintableArea mpa) {

        getMediaPrintables(null);

        if (mediaPrintables != null) {
            for (int i=0; i<mediaPrintables.length; i++) {
                if (mpa.equals(mediaPrintables[i])) {
                    return true;
                }
            }
        }
        return false;
    }
 
Example #27
Source File: Win32PrintService.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean isSupportedMediaPrintableArea(MediaPrintableArea mpa) {

        getMediaPrintables(null);

        if (mediaPrintables != null) {
            for (int i=0; i<mediaPrintables.length; i++) {
                if (mpa.equals(mediaPrintables[i])) {
                    return true;
                }
            }
        }
        return false;
    }
 
Example #28
Source File: RasterPrinterJob.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected PageFormat getPageFormatFromAttributes() {
    Pageable pageable = null;
    if (attributes == null || attributes.isEmpty() ||
        !((pageable = getPageable()) instanceof OpenBook)) {
        return null;
    }

    PageFormat newPf = attributeToPageFormat(
        getPrintService(), attributes);
    PageFormat oldPf = null;
    if ((oldPf = pageable.getPageFormat(0)) != null) {
        // If orientation, media, imageable area attributes are not in
        // "attributes" set, then use respective values of the existing
        // page format "oldPf".
        if (attributes.get(OrientationRequested.class) == null) {
            newPf.setOrientation(oldPf.getOrientation());
        }

        Paper newPaper = newPf.getPaper();
        Paper oldPaper = oldPf.getPaper();
        boolean oldPaperValWasSet = false;
        if (attributes.get(MediaSizeName.class) == null) {
            newPaper.setSize(oldPaper.getWidth(), oldPaper.getHeight());
            oldPaperValWasSet = true;
        }
        if (attributes.get(MediaPrintableArea.class) == null) {
            newPaper.setImageableArea(
                oldPaper.getImageableX(), oldPaper.getImageableY(),
                oldPaper.getImageableWidth(),
                oldPaper.getImageableHeight());
            oldPaperValWasSet = true;
        }
        if (oldPaperValWasSet) {
            newPf.setPaper(newPaper);
        }
    }
    return newPf;
}
 
Example #29
Source File: ImageableAreaTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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!");
    }
}
 
Example #30
Source File: CPrinterJob.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected MediaPrintableArea getDefaultPrintableArea(PageFormat page, double w, double h) {
    final float dpi = 72.0f;
    Paper paper = page.getPaper();
    return new MediaPrintableArea(
            (float) (paper.getImageableX() / dpi),
            (float) (paper.getImageableY() / dpi),
            (float) (paper.getImageableWidth() / dpi),
            (float) (paper.getImageableHeight() / dpi),
            MediaPrintableArea.INCH);
}