Package javax.print.attribute.standard

Examples of javax.print.attribute.standard.MediaPrintableArea


    //return ExtendedPageFormat.getDefaultMediaPrintableArea();
  }

  public static MediaPrintableArea adaptMediaPrintableArea(MediaPrintableArea m,PrintService printService,MediaSizeName mediaSizeName){
    if (mediaSizeName==null) return m; //bigPage
    MediaPrintableArea max=getMaxMediaPrintableArea(printService, mediaSizeName);
    boolean changed=false;
    float x=m.getX(MediaSize.MM),y=m.getY(MediaSize.MM),w=m.getWidth(MediaSize.MM),h=m.getHeight(MediaSize.MM);
    float mx=m.getX(MediaSize.MM),my=m.getY(MediaSize.MM),mw=m.getWidth(MediaSize.MM),mh=m.getHeight(MediaSize.MM);
    if (x<0){
      x=0;
      changed=true;
    }
    if (x>mx){
      x=mx;
      changed=true;
    }
    if (y<0){
      y=0;
      changed=true;
    }
    if (y>my){
      y=my;
      changed=true;
    }
    if (w<0){
      w=0;
      changed=true;
    }
    if (w>mw){
      w=mw;
      changed=true;
    }
    if (h<0){
      h=0;
      changed=true;
    }
    if (h>mh){
      h=mh;
      changed=true;
    }
    if (changed) return new MediaPrintableArea(x,y,w,h,MediaSize.MM);
    else return m;
  }
View Full Code Here


    if (changed) return new MediaPrintableArea(x,y,w,h,MediaSize.MM);
    else return m;
  }

  private static MediaPrintableArea getMaxMediaPrintableArea(PrintService printService,MediaSizeName mediaSizeName){
    MediaPrintableArea area=null;;
    if (mediaSizeName!=null&&!(printService instanceof PDFPrintService)){
      PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
      aset.add(mediaSizeName);
      MediaPrintableArea[] printableArea =(MediaPrintableArea[])printService.getSupportedAttributeValues(MediaPrintableArea.class, null, aset);
      if (printableArea!=null&&printableArea.length==1) area=printableArea[0];
    }
    if (area==null){
      MediaSize size=MediaSize.getMediaSizeForName(mediaSizeName);
      area= new MediaPrintableArea(0,0,size.getX(MediaSize.MM),size.getY(MediaSize.MM),MediaSize.MM); //use paper size
    }
    return area;
  }
View Full Code Here

  public void copy(ExtendedPageFormat p) {
    p.setOrientation(getOrientation());
    p.type=type;
    p.sizeName=sizeName;
    p.size=new PageSize(size.getX(PageSize.MM),size.getY(PageSize.MM),PageSize.MM);
    p.printableArea=new MediaPrintableArea(printableArea.getX(MediaSize.MM),printableArea.getY(MediaSize.MM),printableArea.getWidth(MediaSize.MM),printableArea.getHeight(MediaSize.MM),MediaSize.MM);
    p.updatePaper();
  }
View Full Code Here

      type=s.readInt();
      if (type==BIG_PAGE&&ori==LANDSCAPE){
        //to fix old landscape format
        setOrientation(PORTRAIT);
        size=new PageSize(size.getY(PageSize.MM),size.getX(PageSize.MM),PageSize.MM);
        printableArea=new MediaPrintableArea(printableArea.getY(PageSize.MM),printableArea.getX(PageSize.MM),printableArea.getHeight(PageSize.MM),printableArea.getWidth(PageSize.MM),PageSize.MM);
      }
    }
    updatePaper();
  }
View Full Code Here

        float x2 = (float)(page.getPaper().getImageableX() / 72.0);
        float w = (float)(page.getPaper().getImageableWidth() / 72.0);
        float y2 = (float)(page.getPaper().getImageableY() / 72.0);
        float h = (float)(page.getPaper().getImageableHeight() / 72.0);
        try {
            attributes.add(new MediaPrintableArea(x2, y2, w, h,
                                                Size2DSyntax.INCH));
        } catch (IllegalArgumentException e) {
            // ignore
        }
    }
View Full Code Here

                    float dim[] = size.getSize(units);
                    double w = Math.rint(dim[0]);
                    double h = Math.rint(dim[1]);
                    paper.setSize(w, h);

                    MediaPrintableArea area =
                        (MediaPrintableArea)
                        attributes.get(MediaPrintableArea.class);
                    double ix, iw, iy, ih;

                    if (area != null) {
                        ix = Math.rint(area.getX(Size2DSyntax.INCH) * DPI);
                        iy = Math.rint(area.getY(Size2DSyntax.INCH) * DPI);
                        iw = Math.rint(area.getWidth(Size2DSyntax.INCH) * DPI);
                        ih = Math.rint(area.getHeight(Size2DSyntax.INCH) * DPI);
                    }
                    else {
                        if (w >= 72.0 * 6.0) {
                            ix = 72.0;
                            iw = w - 2 * 72.0;
 
View Full Code Here

         * 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) &&
            isOpenBook(getPageable())) {

            Pageable pageable = getPageable();
            Printable printable = pageable.getPrintable(0);
            PageFormat pf = (PageFormat)pageable.getPageFormat(0).clone();
            Paper paper = pf.getPaper();

            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(mpa, attributes) ||
                (!fidelity & mpa != null)) {
                float [] printableArea =
                    mpa.getPrintableArea(MediaPrintableArea.INCH);
                for (int i=0; i < printableArea.length; i++) {
                    printableArea[i] = printableArea[i] * DPI;
                }
                paper.setImageableArea(printableArea[0], printableArea[1],
                                       printableArea[2], printableArea[3]);
View Full Code Here

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

             }
        } else if (category == MediaPrintableArea.class) {
            float[] prnArea = getMediaPrintableArea(printer, defPaper);
            if (prnArea == null)
                return 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

                    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

TOP

Related Classes of javax.print.attribute.standard.MediaPrintableArea

Copyright © 2018 www.massapicom. 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.