public CustomMediaSizeName(String name, String choice, float width, float length) {
   super(nextValue(name));
   choiceName = choice;
   customEnumTable.add(this);
   mediaName = null;
   try {
     mediaName = MediaSize.findMedia(width, length, MediaSize.INCH);
   } catch (IllegalArgumentException iae) {
   }
 }
示例#2
0
 /**
  * For any given paper, this retrieves the hardware margins, or a reasonable and safe guess if
  * they aren't available.
  */
 public Rectangle2D printableArea(Paper paper) {
   int INCH = MediaSize.INCH;
   Rectangle2D area = null;
   MediaSizeName msn =
       MediaSize.findMedia(
           (float) paper.getWidth(), (float) paper.getHeight(), (int) (INCH / 72.0));
   if (msn != null) {
     PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
     pras.add(msn);
     MediaPrintableArea[] mpa =
         (MediaPrintableArea[])
             service.getSupportedAttributeValues(MediaPrintableArea.class, null, pras);
     if (mpa != null && mpa.length > 0) {
       int MPA_INCH = MediaPrintableArea.INCH;
       area =
           new Rectangle2D(
               mpa[0].getX(MPA_INCH),
               mpa[0].getY(MPA_INCH),
               mpa[0].getWidth(MPA_INCH),
               mpa[0].getHeight(MPA_INCH));
     }
   }
   // If we could not get the area for whatever reason,
   // then go with 0.75" margins unless they are too large
   // ie its a really small paper.
   if (area == null) {
     double pw = (paper.getWidth() / 72.0);
     ;
     double ph = (paper.getHeight() / 72.0);
     double iw, ih;
     if (pw < 3.0) {
       iw = 0.75 * pw;
     } else {
       iw = pw - 1.5;
     }
     if (ph < 3.0) {
       ih = 0.75 * ph;
     } else {
       ih = ph - 1.5;
     }
     double lm = (pw - iw) / 2.0;
     double tm = (ph - ih) / 2.0;
     area = new Rectangle2D(lm, tm, iw, ih);
   }
   return area;
 }
示例#3
0
  private String getMediaName(float width, float height) {
    MediaSizeName msn = MediaSize.findMedia(width, height, Size2DSyntax.MM);

    if (msn == null) return "Unbekannt";

    switch (msn.toString()) {
      case "iso-a0":
        return "DIN A0";
      case "iso-a1":
        return "DIN A1";
      case "iso-a2":
        return "DIN A2";
      case "iso-a3":
        return "DIN A3";
      case "iso-a4":
        return "DIN A4";
      case "iso-a5":
        return "DIN A5";
      case "iso-a6":
        return "DIN A6";
      case "iso-a7":
        return "DIN A7";
      case "iso-a8":
        return "DIN A8";
      case "iso-a9":
        return "DIN A9";
      case "iso-a10":
        return "DIN A10";
      case "iso-b0":
        return "DIN B0";
      case "iso-b1":
        return "DIN B1";
      case "iso-b2":
        return "DIN B2";
      case "iso-b3":
        return "DIN B3";
      case "iso-b4":
        return "DIN B4";
      case "iso-b5":
        return "DIN B5";
      case "iso-b6":
        return "DIN B6";
      case "iso-b7":
        return "DIN B7";
      case "iso-b8":
        return "DIN B8";
      case "iso-b9":
        return "DIN B9";
      case "iso-b10":
        return "DIN B10";
      case "na-letter":
        return "North American Letter";
      case "na-legal":
        return "North American Legal";
      case "na-8x10":
        return "North American 8x10 inch";
      case "na-5x7":
        return "North American 5x7 inch";
      case "executive":
        return "Executive";
      case "folio":
        return "Folio";
      case "invoice":
        return "Invoice";
      case "tabloid":
        return "Tabloid";
      case "ledger":
        return "Ledger";
      case "quarto":
        return "Quarto";
      case "iso-c0":
        return "DIN C0";
      case "iso-c1":
        return "DIN C1";
      case "iso-c2":
        return "DIN C2";
      case "iso-c3":
        return "DIN C3";
      case "iso-c4":
        return "DIN C4";
      case "iso-c5":
        return "DIN C5";
      case "iso-c6":
        return "DIN C6";
      case "iso-designated-long":
        return "ISO Designated Long size";
      case "na-10x13-envelope":
        return "North American 10x13 inch";
      case "na-9x12-envelope":
        return "North American 9x12 inch";
      case "na-number-10-envelope":
        return "North American number 10 business envelope";
      case "na-7x9-envelope":
        return "North American 7x9 inch envelope";
      case "na-9x11-envelope":
        return "North American 9x11 inch envelope";
      case "na-10x14-envelope":
        return "North American 10x14 inch envelope";
      case "na-number-9-envelope":
        return "North American number 9 business envelope";
      case "na-6x9-envelope":
        return "North American 6x9 inch envelope";
      case "na-10x15-envelope":
        return "North American 10x15 inch envelope";
      case "monarch-envelope":
        return "Monarch envelope";
      case "jis-b0":
        return "JIS B0";
      case "jis-b1":
        return "JIS B1";
      case "jis-b2":
        return "JIS B2";
      case "jis-b3":
        return "JIS B3";
      case "jis-b4":
        return "JIS B4";
      case "jis-b5":
        return "JIS B5";
      case "jis-b6":
        return "JIS B6";
      case "jis-b7":
        return "JIS B7";
      case "jis-b8":
        return "JIS B8";
      case "jis-b9":
        return "JIS B9";
      case "jis-b10":
        return "JIS B10";
      case "a":
        return "Engineering ANSI A";
      case "b":
        return "Engineering ANSI B";
      case "c":
        return "Engineering ANSI C";
      case "d":
        return "Engineering ANSI D";
      case "e":
        return "Engineering ANSI E";
      case "f":
        return "Engineering ANSI F";
      case "arch-a":
        return "Architectural ANSI A";
      case "arch-b":
        return "Architectural ANSI B";
      case "arch-c":
        return "Architectural ANSI C";
      case "arch-d":
        return "Architectural ANSI D";
      case "arch-e":
        return "Architectural ANSI E";
      case "japanese-postcard":
        return "Japanese Postcard";
      case "oufuko-postcard":
        return "Oufuko Postcard";
      case "italian-envelope":
        return "Italian Envelope";
      case "personal-envelope":
        return "Personal Envelope";
      case "na-number-11-envelope":
        return "North American Number 11 Envelope";
      case "na-number-12-envelope":
        return "North American Number 12 Envelope";
      case "na-number-14-envelope":
        return "North American Number 14 Envelope";
      default:
        return "Unbekannt";
    }
  }