541 PageFormat page = defaultPage();
542
543 if (service == null) {
544 return page;
545 }
546
547 OrientationRequested orient = (OrientationRequested)
548 attSet.get(OrientationRequested.class);
549 if (orient == null) {
550 orient = (OrientationRequested)
551 service.getDefaultAttributeValue(OrientationRequested.class);
552 }
553 if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
554 page.setOrientation(PageFormat.REVERSE_LANDSCAPE);
555 } else if (orient == OrientationRequested.LANDSCAPE) {
556 page.setOrientation(PageFormat.LANDSCAPE);
557 } else {
558 page.setOrientation(PageFormat.PORTRAIT);
559 }
560
561 Media media = (Media)attSet.get(Media.class);
562 if (media == null) {
563 media =
564 (Media)service.getDefaultAttributeValue(Media.class);
565 }
566 if (!(media instanceof MediaSizeName)) {
567 media = MediaSizeName.NA_LETTER;
568 }
569 MediaSize size =
570 MediaSize.getMediaSizeForName((MediaSizeName)media);
571 if (size == null) {
572 size = MediaSize.NA.LETTER;
573 }
574 Paper paper = new Paper();
575 float dim[] = size.getSize(1); //units == 1 to avoid FP error
576 double w = Math.rint((dim[0]*72.0)/Size2DSyntax.INCH);
577 double h = Math.rint((dim[1]*72.0)/Size2DSyntax.INCH);
578 paper.setSize(w, h);
579 MediaPrintableArea area =
580 (MediaPrintableArea)
594 area.getHeight(MediaPrintableArea.INCH) * DPI);
595 }
596 else {
597 if (w >= 72.0 * 6.0) {
598 ix = 72.0;
599 iw = w - 2 * 72.0;
600 } else {
601 ix = w / 6.0;
602 iw = w * 0.75;
603 }
604 if (h >= 72.0 * 6.0) {
605 iy = 72.0;
606 ih = h - 2 * 72.0;
607 } else {
608 iy = h / 6.0;
609 ih = h * 0.75;
610 }
611 }
612 paper.setImageableArea(ix, iy, iw, ih);
613 page.setPaper(paper);
614 return page;
615 }
616
617 protected void updatePageAttributes(PrintService service,
618 PageFormat page) {
619 if (this.attributes == null) {
620 this.attributes = new HashPrintRequestAttributeSet();
621 }
622
623 updateAttributesWithPageFormat(service, page, this.attributes);
624 }
625
626 protected void updateAttributesWithPageFormat(PrintService service,
627 PageFormat page,
628 PrintRequestAttributeSet pageAttributes) {
629 if (service == null || page == null || pageAttributes == null) {
630 return;
631 }
632
633 float x = (float)Math.rint(
634 (page.getPaper().getWidth()*Size2DSyntax.INCH)/
|
541 PageFormat page = defaultPage();
542
543 if (service == null) {
544 return page;
545 }
546
547 OrientationRequested orient = (OrientationRequested)
548 attSet.get(OrientationRequested.class);
549 if (orient == null) {
550 orient = (OrientationRequested)
551 service.getDefaultAttributeValue(OrientationRequested.class);
552 }
553 if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
554 page.setOrientation(PageFormat.REVERSE_LANDSCAPE);
555 } else if (orient == OrientationRequested.LANDSCAPE) {
556 page.setOrientation(PageFormat.LANDSCAPE);
557 } else {
558 page.setOrientation(PageFormat.PORTRAIT);
559 }
560
561 setPaperFromAttributes(page, service, attSet);
562 return page;
563 }
564
565 protected void setPaperFromAttributes(PageFormat page,
566 PrintService service, PrintRequestAttributeSet attSet) {
567 Media media = (Media)attSet.get(Media.class);
568 if (media == null) {
569 media =
570 (Media)service.getDefaultAttributeValue(Media.class);
571 }
572 if (!(media instanceof MediaSizeName)) {
573 media = MediaSizeName.NA_LETTER;
574 }
575 MediaSize size =
576 MediaSize.getMediaSizeForName((MediaSizeName)media);
577 if (size == null) {
578 size = MediaSize.NA.LETTER;
579 }
580 Paper paper = new Paper();
581 float dim[] = size.getSize(1); //units == 1 to avoid FP error
582 double w = Math.rint((dim[0]*72.0)/Size2DSyntax.INCH);
583 double h = Math.rint((dim[1]*72.0)/Size2DSyntax.INCH);
584 paper.setSize(w, h);
585 MediaPrintableArea area =
586 (MediaPrintableArea)
600 area.getHeight(MediaPrintableArea.INCH) * DPI);
601 }
602 else {
603 if (w >= 72.0 * 6.0) {
604 ix = 72.0;
605 iw = w - 2 * 72.0;
606 } else {
607 ix = w / 6.0;
608 iw = w * 0.75;
609 }
610 if (h >= 72.0 * 6.0) {
611 iy = 72.0;
612 ih = h - 2 * 72.0;
613 } else {
614 iy = h / 6.0;
615 ih = h * 0.75;
616 }
617 }
618 paper.setImageableArea(ix, iy, iw, ih);
619 page.setPaper(paper);
620 }
621
622 protected void updatePageAttributes(PrintService service,
623 PageFormat page) {
624 if (this.attributes == null) {
625 this.attributes = new HashPrintRequestAttributeSet();
626 }
627
628 updateAttributesWithPageFormat(service, page, this.attributes);
629 }
630
631 protected void updateAttributesWithPageFormat(PrintService service,
632 PageFormat page,
633 PrintRequestAttributeSet pageAttributes) {
634 if (service == null || page == null || pageAttributes == null) {
635 return;
636 }
637
638 float x = (float)Math.rint(
639 (page.getPaper().getWidth()*Size2DSyntax.INCH)/
|