views:

16

answers:

0

I have an odd problem that seems to be specific to Mac computers. I have a prog that prints the content of an AWT drawing surface to an A3 sheet of paper. On Linux and windows machines the output is OK. Printing from a Mac I get the same dialog with the same preset parameters, the printer prints on an A3 sheet of paper as expected, but for some reason the image is scaled to fit an A4 area. Below are the relevant sections of code:

public void print() {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    PageFormat format = new PageFormat();
    format.setOrientation(PageFormat.LANDSCAPE);

    double margin = 18; // quarter inch
    double m2 = margin * 2;
    Paper paper = format.getPaper();
    paper.setSize(16.54 * 72, 11.69 * 72); // A3 Landscape
    paper.setImageableArea(margin, margin,  paper.getWidth()-m2, paper.getHeight()-m2);
    format.setPaper(paper);
    printJob.setPrintable(this, format);

    PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
    attributes.add(MediaSizeName.ISO_A3);
    attributes.add(OrientationRequested.LANDSCAPE);
    attributes.add(new MediaPrintableArea((int)margin, (int)margin,
            (int)(paper.getWidth()-m2), (int)(paper.getHeight()-m2),
            MediaPrintableArea.INCH));

    if(printJob.printDialog(attributes) ){
      try {
        printJob.print(attributes);
      } catch(PrinterException pe) {
        pe.printStackTrace();
      }
    }
  }

  public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
    if (pageIndex > 0) {
      return(NO_SUCH_PAGE);
    } else {
      Graphics2D g2d = (Graphics2D)g;
      g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
      if(this.componentToBePrinted instanceof PlannerView){
          setScale(g2d);
      }
      disableDoubleBuffering(componentToBePrinted);
      componentToBePrinted.paint(g2d);
      enableDoubleBuffering(componentToBePrinted);
      return(PAGE_EXISTS);
    }
  }

  public void setScale(Graphics2D g2d){
      PlannerView planner = (PlannerView)this.componentToBePrinted;
      planner.resetZoom();
      double scale = 1.0 / planner.getRowLength();
      scale *= 4.0; 
      g2d.scale(scale, scale);
  }

Does anyone know what could be causing this?

Cheers.