Пример #1
0
 /**
  * Creates a PDF document.
  *
  * @param filename the path to the new PDF document
  * @throws DocumentException
  * @throws IOException
  */
 public void createPdf(String filename) throws IOException, DocumentException {
   // step 1
   Document document = new Document(new Rectangle(360, 360));
   // step 2
   PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
   // step 3
   document.open();
   writer.addJavaScript(Utilities.readFileToString(RESOURCE));
   // step 4
   // add the keys for the digits
   for (int i = 0; i < 10; i++) {
     addPushButton(writer, digits[i], String.valueOf(i), "this.augment(" + i + ")");
   }
   // add the keys for the operators
   addPushButton(writer, plus, "+", "this.register('+')");
   addPushButton(writer, minus, "-", "this.register('-')");
   addPushButton(writer, mult, "x", "this.register('*')");
   addPushButton(writer, div, ":", "this.register('/')");
   addPushButton(writer, equals, "=", "this.calculateResult()");
   // add the other keys
   addPushButton(writer, clearEntry, "CE", "this.reset(false)");
   addPushButton(writer, clear, "C", "this.reset(true)");
   addTextField(writer, result, "result");
   addTextField(writer, move, "move");
   // step 5
   document.close();
 }
Пример #2
0
 /**
  * Gets the width of a <CODE>String</CODE> in normalized 1000 units.
  *
  * @param text the <CODE>String</CODE> to get the width of
  * @return the width in normalized 1000 units
  */
 @Override
 public int getWidth(String text) {
   if (vertical) return text.length() * 1000;
   int total = 0;
   if (fontSpecific) {
     char cc[] = text.toCharArray();
     int len = cc.length;
     for (int k = 0; k < len; ++k) {
       char c = cc[k];
       if ((c & 0xff00) == 0 || (c & 0xff00) == 0xf000) total += getRawWidth(c & 0xff, null);
     }
   } else {
     int len = text.length();
     for (int k = 0; k < len; ++k) {
       if (Utilities.isSurrogatePair(text, k)) {
         total += getRawWidth(Utilities.convertToUtf32(text, k), encoding);
         ++k;
       } else total += getRawWidth(text.charAt(k), encoding);
     }
   }
   return total;
 }
Пример #3
0
 /**
  * Reads a BMP from a file.
  *
  * @param file the file
  * @throws IOException on error
  * @return the image
  */
 public static Image getImage(String file) throws IOException {
   return getImage(Utilities.toURL(file));
 }