modules/graphics/src/main/java/javafx/print/Printer.java

Print this page




 236      * @param orient The orientation to use
 237      * @param mType the margin type to use
 238      * @return PageLayout based on the specified parameters.
 239      * @throws NullPointerException if any of the parameters are null.
 240      */
 241     public PageLayout createPageLayout(Paper paper, PageOrientation orient,
 242                         MarginType mType) {
 243 
 244         if (paper == null || orient == null || mType == null) {
 245             throw new NullPointerException("Parameters cannot be null");
 246         }
 247 
 248         // TBD: Adjust paper to a supported one first.
 249         Rectangle2D imgArea = impl.printableArea(paper);
 250         double width = paper.getWidth() / 72.0;
 251         double height = paper.getHeight() / 72.0;
 252         double plm = imgArea.getMinX();
 253         double ptm = imgArea.getMinY();
 254         double prm = width - imgArea.getMaxX();
 255         double pbm = height - imgArea.getMaxY();





 256 
 257         switch (mType) {
 258         case DEFAULT:
 259             plm = (plm <= 0.75) ? 0.75 : plm;
 260             prm = (prm <= 0.75) ? 0.75 : prm;
 261             ptm = (ptm <= 0.75) ? 0.75 : ptm;
 262             pbm = (pbm <= 0.75) ? 0.75 : pbm;
 263             break;
 264         case EQUAL: {
 265             double maxH = (double)Math.max(plm, prm);
 266             double maxV = (double)Math.max(ptm, pbm);
 267             double maxM = (double)Math.max(maxH, maxV);
 268             plm = prm = ptm = pbm = maxM;
 269             break;
 270         }
 271         case EQUAL_OPPOSITES: {
 272             double maxH = (double)Math.max(plm, prm);
 273             double maxV = (double)Math.max(ptm, pbm);
 274             plm = prm = maxH;
 275             ptm = pbm = maxV;




 236      * @param orient The orientation to use
 237      * @param mType the margin type to use
 238      * @return PageLayout based on the specified parameters.
 239      * @throws NullPointerException if any of the parameters are null.
 240      */
 241     public PageLayout createPageLayout(Paper paper, PageOrientation orient,
 242                         MarginType mType) {
 243 
 244         if (paper == null || orient == null || mType == null) {
 245             throw new NullPointerException("Parameters cannot be null");
 246         }
 247 
 248         // TBD: Adjust paper to a supported one first.
 249         Rectangle2D imgArea = impl.printableArea(paper);
 250         double width = paper.getWidth() / 72.0;
 251         double height = paper.getHeight() / 72.0;
 252         double plm = imgArea.getMinX();
 253         double ptm = imgArea.getMinY();
 254         double prm = width - imgArea.getMaxX();
 255         double pbm = height - imgArea.getMaxY();
 256         // fix for FP error
 257         if (Math.abs(plm) < 0.01) plm = 0;
 258         if (Math.abs(prm) < 0.01) prm = 0;
 259         if (Math.abs(ptm) < 0.01) ptm = 0;
 260         if (Math.abs(pbm) < 0.01) pbm = 0;
 261 
 262         switch (mType) {
 263         case DEFAULT:
 264             plm = (plm <= 0.75) ? 0.75 : plm;
 265             prm = (prm <= 0.75) ? 0.75 : prm;
 266             ptm = (ptm <= 0.75) ? 0.75 : ptm;
 267             pbm = (pbm <= 0.75) ? 0.75 : pbm;
 268             break;
 269         case EQUAL: {
 270             double maxH = (double)Math.max(plm, prm);
 271             double maxV = (double)Math.max(ptm, pbm);
 272             double maxM = (double)Math.max(maxH, maxV);
 273             plm = prm = ptm = pbm = maxM;
 274             break;
 275         }
 276         case EQUAL_OPPOSITES: {
 277             double maxH = (double)Math.max(plm, prm);
 278             double maxV = (double)Math.max(ptm, pbm);
 279             plm = prm = maxH;
 280             ptm = pbm = maxV;