Examples of MediaPrintableArea


Examples of javax.print.attribute.standard.MediaPrintableArea

        float ySize = mediaSize.getY(Size2DSyntax.INCH) * 72;
       
        Paper pdfPaper = new Paper();
        pdfPaper.setSize(xSize, ySize);
               
        MediaPrintableArea area = (MediaPrintableArea) printingDevice.getDefaultAttributeValue(MediaPrintableArea.class);
       
        if(testFlag && area==null)
        System.out.println("Area is null");
       
        float[] imagable;
       
        //On my cheap tesco printer this return null, so accounted for that case.
//        if(area != null) {
//            imagable = area.getPrintableArea(Size2DSyntax.INCH);
//        }
//        else {
          PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
          attributes.add(mediaSizeName);
          MediaPrintableArea areas[] = (MediaPrintableArea[]) printingDevice.getSupportedAttributeValues(MediaPrintableArea.class, null, attributes);
         
          if(testFlag && areas==null)
          System.out.println("Printable Area array is null");
         
          imagable = areas[0].getPrintableArea(Size2DSyntax.INCH);
View Full Code Here

Examples of javax.print.attribute.standard.MediaPrintableArea

        float iw = (float)(page.getPaper().getImageableWidth()/DPI);
        float iy = (float)(page.getPaper().getImageableY()/DPI);
        float ih = (float)(page.getPaper().getImageableHeight()/DPI);
        if (ix < 0) ix = 0f; if (iy < 0) iy = 0f;
        try {
            attributes.add(new MediaPrintableArea(ix, iy, iw, ih,
                                                  MediaPrintableArea.INCH));
        } catch (IllegalArgumentException iae) {
        }
    }
View Full Code Here

Examples of javax.print.attribute.standard.MediaPrintableArea

            Paper paper = new Paper();
            float dim[] = size.getSize(1); //units == 1 to avoid FP error
            double w = Math.rint((dim[0]*72.0)/Size2DSyntax.INCH);
            double h = Math.rint((dim[1]*72.0)/Size2DSyntax.INCH);
            paper.setSize(w, h);
            MediaPrintableArea area =
                (MediaPrintableArea)
                attributes.get(MediaPrintableArea.class);
            double ix, iw, iy, ih;

            if (area != null) {
                // Should pass in same unit as updatePageAttributes
                // to avoid rounding off errors.
                ix = Math.rint(
                               area.getX(MediaPrintableArea.INCH) * DPI);
                iy = Math.rint(
                               area.getY(MediaPrintableArea.INCH) * DPI);
                iw = Math.rint(
                               area.getWidth(MediaPrintableArea.INCH) * DPI);
                ih = Math.rint(
                               area.getHeight(MediaPrintableArea.INCH) * DPI);
            }
            else {
                if (w >= 72.0 * 6.0) {
                    ix = 72.0;
                    iw = w - 2 * 72.0;
 
View Full Code Here

Examples of javax.print.attribute.standard.MediaPrintableArea

         * This is the case when we use the values from the attribute set.
         */
        Media media = (Media)attributes.get(Media.class);
        OrientationRequested orientReq =
           (OrientationRequested)attributes.get(OrientationRequested.class);
        MediaPrintableArea mpa =
            (MediaPrintableArea)attributes.get(MediaPrintableArea.class);

        if ((orientReq != null || media != null || mpa != null) &&
            getPageable() instanceof OpenBook) {

            /* We could almost(!) use PrinterJob.getPageFormat() except
             * here we need to start with the PageFormat from the OpenBook :
             */
            Pageable pageable = getPageable();
            Printable printable = pageable.getPrintable(0);
            PageFormat pf = (PageFormat)pageable.getPageFormat(0).clone();
            Paper paper = pf.getPaper();

            /* If there's a media but no media printable area, we can try
             * to retrieve the default value for mpa and use that.
             */
            if (mpa == null && media != null &&
                service.
                isAttributeCategorySupported(MediaPrintableArea.class)) {
                Object mpaVals = service.
                    getSupportedAttributeValues(MediaPrintableArea.class,
                                                null, attributes);
                if (mpaVals instanceof MediaPrintableArea[] &&
                    ((MediaPrintableArea[])mpaVals).length > 0) {
                    mpa = ((MediaPrintableArea[])mpaVals)[0];
                }
            }

            if (isSupportedValue(orientReq, attributes) ||
                (!fidelity && orientReq != null)) {
                int orient;
                if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
                    orient = PageFormat.REVERSE_LANDSCAPE;
                } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
                    orient = PageFormat.LANDSCAPE;
                } else {
                    orient = PageFormat.PORTRAIT;
                }
                pf.setOrientation(orient);
            }

            if (isSupportedValue(media, attributes) ||
                (!fidelity && media != null)) {
                if (media instanceof MediaSizeName) {
                    MediaSizeName msn = (MediaSizeName)media;
                    MediaSize msz = MediaSize.getMediaSizeForName(msn);
                    if (msz != null) {
                        float paperWid =  msz.getX(MediaSize.INCH) * 72.0f;
                        float paperHgt =  msz.getY(MediaSize.INCH) * 72.0f;
                        paper.setSize(paperWid, paperHgt);
                        if (mpa == null) {
                            paper.setImageableArea(72.0, 72.0,
                                                   paperWid-144.0,
                                                   paperHgt-144.0);
                        }
                    }
                }
            }

            if (isSupportedValue(mpa, attributes) ||
                (!fidelity && mpa != null)) {
                float [] printableArea =
                    mpa.getPrintableArea(MediaPrintableArea.INCH);
                for (int i=0; i < printableArea.length; i++) {
                    printableArea[i] = printableArea[i]*72.0f;
                }
                paper.setImageableArea(printableArea[0], printableArea[1],
                                       printableArea[2], printableArea[3]);
View Full Code Here

Examples of javax.print.attribute.standard.MediaPrintableArea

                if (added && !queryFailure) {
                    prnArea=getMediaPrintableArea(printer,
                                                  ((Integer)idList.get(i)).intValue());
                    if (prnArea != null) {
                        try {
                            MediaPrintableArea mpa =
                                new MediaPrintableArea(prnArea[0],
                                                       prnArea[1],
                                                       prnArea[2],
                                                       prnArea[3],
                                                       MediaPrintableArea.INCH);
                            printableList.add(mpa);
View Full Code Here

Examples of javax.print.attribute.standard.MediaPrintableArea

                !isSupportedMedia(msn) && mediaSizeNames != null) {
                defPaper = findPaperID(mediaSizeNames[0]);
            }
            float[] prnArea = getMediaPrintableArea(printer, defPaper);
            if (prnArea != null) {
                MediaPrintableArea printableArea = null;
                try {
                    printableArea = new MediaPrintableArea(prnArea[0],
                                                           prnArea[1],
                                                           prnArea[2],
                                                           prnArea[3],
                                                           MediaPrintableArea.INCH);
                } catch (IllegalArgumentException e) {
View Full Code Here

Examples of javax.print.attribute.standard.MediaPrintableArea

                    MediaSize ms =
                      MediaSize.getMediaSizeForName((MediaSizeName)mediaName);

                    if (ms != null) {
                        arr[0] = new MediaPrintableArea(0, 0,
                                                        ms.getX(MediaSize.INCH),
                                                        ms.getY(MediaSize.INCH),
                                                        MediaPrintableArea.INCH);
                        return arr;
                    } else {
View Full Code Here

Examples of javax.print.attribute.standard.MediaPrintableArea

        if (service == null || attributes == null) {
            return pf;
        }

        Media media = (Media)attributes.get(Media.class);
        MediaPrintableArea mpa =
            (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
        OrientationRequested orientReq =
           (OrientationRequested)attributes.get(OrientationRequested.class);

        if (media == null && mpa == null && orientReq == null) {
           return pf;
        }
        Paper paper = pf.getPaper();

        /* If there's a media but no media printable area, we can try
         * to retrieve the default value for mpa and use that.
         */
        if (mpa == null && media != null &&
            service.isAttributeCategorySupported(MediaPrintableArea.class)) {
            Object mpaVals =
                service.getSupportedAttributeValues(MediaPrintableArea.class,
                                                    null, attributes);
            if (mpaVals instanceof MediaPrintableArea[] &&
                ((MediaPrintableArea[])mpaVals).length > 0) {
                mpa = ((MediaPrintableArea[])mpaVals)[0];
            }
        }

        if (media != null &&
            service.isAttributeValueSupported(media, null, attributes)) {
            if (media instanceof MediaSizeName) {
                MediaSizeName msn = (MediaSizeName)media;
                MediaSize msz = MediaSize.getMediaSizeForName(msn);
                if (msz != null) {
                    double inch = 72.0;
                    double paperWid = msz.getX(MediaSize.INCH) * inch;
                    double paperHgt = msz.getY(MediaSize.INCH) * inch;
                    paper.setSize(paperWid, paperHgt);
                    if (mpa == null) {
                        paper.setImageableArea(inch, inch,
                                               paperWid-2*inch,
                                               paperHgt-2*inch);
                    }
                }
            }
        }

        if (mpa != null &&
            service.isAttributeValueSupported(mpa, null, attributes)) {
            float [] printableArea =
                mpa.getPrintableArea(MediaPrintableArea.INCH);
            for (int i=0; i < printableArea.length; i++) {
                printableArea[i] = printableArea[i]*72.0f;
            }
            paper.setImageableArea(printableArea[0], printableArea[1],
                                   printableArea[2], printableArea[3]);
View Full Code Here

Examples of javax.print.attribute.standard.MediaPrintableArea

                ih = MediaSize.NA.LETTER.getY(Size2DSyntax.INCH) - 2*margin;
            } else {
                iw = MediaSize.ISO.A4.getX(Size2DSyntax.INCH) - 2*margin;
                ih = MediaSize.ISO.A4.getY(Size2DSyntax.INCH) - 2*margin;
            }
            return new MediaPrintableArea(margin, margin, iw, ih,
                                          MediaPrintableArea.INCH);
        } else if (category == OrientationRequested.class) {
            return OrientationRequested.PORTRAIT;
        } else if (category == PageRanges.class) {
            return new PageRanges(1, Integer.MAX_VALUE);
View Full Code Here

Examples of javax.print.attribute.standard.MediaPrintableArea

                    xmargin = w/10;
                }
                if (h < 5f) {
                    ymargin = h/10;
                }
                arr[0] = new MediaPrintableArea(xmargin, ymargin,
                                                w - 2*xmargin,
                                                h - 2*ymargin,
                                                MediaSize.INCH);
                return arr;
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.