< prev index next >

test/java/awt/print/PageFormat/PageFormatFromAttributes.java

Print this page




  67         boolean ok = true;
  68         switch (pf.getOrientation()) {
  69         case PageFormat.PORTRAIT :
  70             ok = orient == OrientationRequested.PORTRAIT;
  71             break;
  72         case PageFormat.LANDSCAPE :
  73             ok = orient == OrientationRequested.LANDSCAPE;
  74             break;
  75         case PageFormat.REVERSE_LANDSCAPE :
  76             ok = orient == OrientationRequested.REVERSE_LANDSCAPE;
  77             break;
  78         }
  79         if (!ok) {
  80             throw new RuntimeException("orientation not as specified");
  81         }
  82         MediaSize mediaSize = MediaSize.getMediaSizeForName(media);
  83         if (mediaSize == null) {
  84             throw new RuntimeException("expected a media size");
  85         }
  86         double units = Size2DSyntax.INCH/72.0;
  87         int w = (int)(mediaSize.getX(1)/units);
  88         int h = (int)(mediaSize.getY(1)/units);
  89         Paper paper = pf.getPaper();
  90         int pw = (int)paper.getWidth();
  91         int ph = (int)paper.getHeight();
  92         if (pw != w || ph != h) {

  93             throw new RuntimeException("size not as specified");
  94         }
  95     }
  96 }


  67         boolean ok = true;
  68         switch (pf.getOrientation()) {
  69         case PageFormat.PORTRAIT :
  70             ok = orient == OrientationRequested.PORTRAIT;
  71             break;
  72         case PageFormat.LANDSCAPE :
  73             ok = orient == OrientationRequested.LANDSCAPE;
  74             break;
  75         case PageFormat.REVERSE_LANDSCAPE :
  76             ok = orient == OrientationRequested.REVERSE_LANDSCAPE;
  77             break;
  78         }
  79         if (!ok) {
  80             throw new RuntimeException("orientation not as specified");
  81         }
  82         MediaSize mediaSize = MediaSize.getMediaSizeForName(media);
  83         if (mediaSize == null) {
  84             throw new RuntimeException("expected a media size");
  85         }
  86         double units = Size2DSyntax.INCH/72.0;
  87         double w = mediaSize.getX(1) / units;
  88         double h = mediaSize.getY(1) / units;
  89         Paper paper = pf.getPaper();
  90         double pw = paper.getWidth();
  91         double ph = paper.getHeight();
  92         if (Math.round(pw) != Math.round(w) || 
  93             Math.round(ph) != Math.round(h)) {
  94             throw new RuntimeException("size not as specified");
  95         }
  96     }
  97 }
< prev index next >