Esempio n. 1
0
  private void importTTFButtonActionPerformed(ActionEvent evt) {
    TreeItem item = mainPanel.tagTree.getCurrentTreeItem();
    if (item instanceof FontTag) {
      FontTag ft = (FontTag) item;

      JFileChooser fc = new JFileChooser();
      fc.setCurrentDirectory(new File(Configuration.lastOpenDir.get()));
      FileFilter ttfFilter =
          new FileFilter() {
            @Override
            public boolean accept(File f) {
              return (f.getName().toLowerCase().endsWith(".ttf")) || (f.isDirectory());
            }

            @Override
            public String getDescription() {
              return "TTF files";
            }
          };
      fc.setFileFilter(ttfFilter);

      fc.setAcceptAllFileFilterUsed(false);
      JFrame fr = new JFrame();
      View.setWindowIcon(fr);
      int returnVal = fc.showOpenDialog(fr);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        Configuration.lastOpenDir.set(
            Helper.fixDialogFile(fc.getSelectedFile()).getParentFile().getAbsolutePath());
        File selfile = Helper.fixDialogFile(fc.getSelectedFile());
        Set<Integer> selChars = new HashSet<>();
        try {
          Font f = Font.createFont(Font.TRUETYPE_FONT, selfile);
          int required[] = new int[] {0x0001, 0x0000, 0x000D, 0x0020};
          loopi:
          for (char i = 0; i < Character.MAX_VALUE; i++) {
            for (int r : required) {
              if (r == i) {
                continue loopi;
              }
            }
            if (f.canDisplay((int) i)) {
              selChars.add((int) i);
            }
          }
          fontAddChars(ft, selChars, f);
          mainPanel.reload(true);
        } catch (FontFormatException ex) {
          JOptionPane.showMessageDialog(mainPanel, "Invalid TTF font");
        } catch (IOException ex) {
          Logger.getLogger(FontPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
    }
  }
Esempio n. 2
0
  private void fontAddCharsButtonActionPerformed(ActionEvent evt) {
    String newchars = fontAddCharactersField.getText();

    TreeItem item = mainPanel.tagTree.getCurrentTreeItem();
    if (item instanceof FontTag) {
      Set<Integer> selChars = new TreeSet<>();
      for (int c = 0; c < newchars.length(); c++) {
        selChars.add(newchars.codePointAt(c));
      }
      fontAddChars((FontTag) item, selChars, ((FontFace) fontFaceSelection.getSelectedItem()).font);
      fontAddCharactersField.setText("");
      mainPanel.reload(true);
    }
  }
Esempio n. 3
0
 private void fontEmbedButtonActionPerformed(ActionEvent evt) {
   TreeItem item = mainPanel.tagTree.getCurrentTreeItem();
   if (item instanceof FontTag) {
     FontTag ft = (FontTag) item;
     FontEmbedDialog fed =
         new FontEmbedDialog(
             (FontFace) fontFaceSelection.getSelectedItem(), fontAddCharactersField.getText());
     if (fed.showDialog() == AppDialog.OK_OPTION) {
       Set<Integer> selChars = fed.getSelectedChars();
       if (!selChars.isEmpty()) {
         Font selFont = fed.getSelectedFont();
         updateTextsCheckBox.setSelected(fed.hasUpdateTexts());
         fontFamilyNameSelection.setSelectedItem(new FontFamily(selFont));
         fontFaceSelection.setSelectedItem(new FontFace(selFont));
         fontAddChars(ft, selChars, selFont);
         fontAddCharactersField.setText("");
         mainPanel.reload(true);
       }
     }
   }
 }