Java Code Examples for java.awt.GraphicsEnvironment#getAllFonts()

The following examples show how to use java.awt.GraphicsEnvironment#getAllFonts() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelvLtOblTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String os = System.getProperty("os.name");
    if (!os.startsWith("Mac")) {
         return;
    }
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    for (int i=0; i<fonts.length; i++) {
        if (fonts[i].getPSName().equals("Helvetica-LightOblique")) {
             helvFont = fonts[i];
             break;
        }
    }
    if (helvFont == null) {
        return;
    }
    final HelvLtOblTest test = new HelvLtOblTest();
    SwingUtilities.invokeLater(() -> {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add("Center", test);
        f.pack();
        f.setVisible(true);
    });
    test.compareImages();
}
 
Example 2
Source File: HelvLtOblTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String os = System.getProperty("os.name");
    if (!os.startsWith("Mac")) {
         return;
    }
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    for (int i=0; i<fonts.length; i++) {
        if (fonts[i].getPSName().equals("Helvetica-LightOblique")) {
             helvFont = fonts[i];
             break;
        }
    }
    if (helvFont == null) {
        return;
    }
    final HelvLtOblTest test = new HelvLtOblTest();
    SwingUtilities.invokeLater(() -> {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add("Center", test);
        f.pack();
        f.setVisible(true);
    });
    test.compareImages();
}
 
Example 3
Source File: HelvLtOblTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String os = System.getProperty("os.name");
    if (!os.startsWith("Mac")) {
         return;
    }
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    for (int i=0; i<fonts.length; i++) {
        if (fonts[i].getPSName().equals("Helvetica-LightOblique")) {
             helvFont = fonts[i];
             break;
        }
    }
    if (helvFont == null) {
        return;
    }
    final HelvLtOblTest test = new HelvLtOblTest();
    SwingUtilities.invokeLater(() -> {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add("Center", test);
        f.pack();
        f.setVisible(true);
    });
    test.compareImages();
}
 
Example 4
Source File: HelvLtOblTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String os = System.getProperty("os.name");
    if (!os.startsWith("Mac")) {
         return;
    }
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    for (int i=0; i<fonts.length; i++) {
        if (fonts[i].getPSName().equals("Helvetica-LightOblique")) {
             helvFont = fonts[i];
             break;
        }
    }
    if (helvFont == null) {
        return;
    }
    final HelvLtOblTest test = new HelvLtOblTest();
    SwingUtilities.invokeLater(() -> {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add("Center", test);
        f.pack();
        f.setVisible(true);
    });
    test.compareImages();
}
 
Example 5
Source File: HelvLtOblTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String os = System.getProperty("os.name");
    if (!os.startsWith("Mac")) {
         return;
    }
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    for (int i=0; i<fonts.length; i++) {
        if (fonts[i].getPSName().equals("Helvetica-LightOblique")) {
             helvFont = fonts[i];
             break;
        }
    }
    if (helvFont == null) {
        return;
    }
    final HelvLtOblTest test = new HelvLtOblTest();
    SwingUtilities.invokeLater(() -> {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add("Center", test);
        f.pack();
        f.setVisible(true);
    });
    test.compareImages();
}
 
Example 6
Source File: HelvLtOblTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String os = System.getProperty("os.name");
    if (!os.startsWith("Mac")) {
         return;
    }
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    for (int i=0; i<fonts.length; i++) {
        if (fonts[i].getPSName().equals("Helvetica-LightOblique")) {
             helvFont = fonts[i];
             break;
        }
    }
    if (helvFont == null) {
        return;
    }
    final HelvLtOblTest test = new HelvLtOblTest();
    SwingUtilities.invokeLater(() -> {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add("Center", test);
        f.pack();
        f.setVisible(true);
    });
    test.compareImages();
}
 
Example 7
Source File: PrintAllFonts.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        String[] instructions =
        {
            "You must have a printer available to perform this test and should use Win 98.",
            "This bug is system dependent and is not always reproducible.",
            " ",
            "A passing test will have all text printed with correct font style.",
        };

        Sysout.createDialog( );
        Sysout.printInstructions( instructions );

        GraphicsEnvironment ge =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
        allFonts = ge.getAllFonts();

        PrinterJob pj = PrinterJob.getPrinterJob();
        pj.setPrintable(new PrintAllFonts());
        if (pj.printDialog()) {
           pj.print();
        }
    }
 
Example 8
Source File: HelvLtOblTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String os = System.getProperty("os.name");
    if (!os.startsWith("Mac")) {
         return;
    }
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    for (int i=0; i<fonts.length; i++) {
        if (fonts[i].getPSName().equals("Helvetica-LightOblique")) {
             helvFont = fonts[i];
             break;
        }
    }
    if (helvFont == null) {
        return;
    }
    final HelvLtOblTest test = new HelvLtOblTest();
    SwingUtilities.invokeLater(() -> {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add("Center", test);
        f.pack();
        f.setVisible(true);
    });
    test.compareImages();
}
 
Example 9
Source File: HelvLtOblTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String os = System.getProperty("os.name");
    if (!os.startsWith("Mac")) {
         return;
    }
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    for (int i=0; i<fonts.length; i++) {
        if (fonts[i].getPSName().equals("Helvetica-LightOblique")) {
             helvFont = fonts[i];
             break;
        }
    }
    if (helvFont == null) {
        return;
    }
    final HelvLtOblTest test = new HelvLtOblTest();
    SwingUtilities.invokeLater(() -> {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add("Center", test);
        f.pack();
        f.setVisible(true);
    });
    test.compareImages();
}
 
Example 10
Source File: GuiHelper.java    From binnavi with Apache License 2.0 5 votes vote down vote up
public static String getMonospaceFont() {
  final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
  final Font[] allfonts = env.getAllFonts();

  for (final Font font : allfonts) {
    if (font.getName().equals("Courier New")) {
      return "Courier New";
    }
  }

  return Font.MONOSPACED;
}
 
Example 11
Source File: AgnUtils.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Set<String> getAvailableFonts() {
	GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
	Set<String> availableFonts = new HashSet<>();
	for (Font font : e.getAllFonts()) {
		availableFonts.add(font.getFontName());
	}
	return availableFonts;
}
 
Example 12
Source File: PhoneticExtensionsGlyphTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static boolean canDisplayPhoneticChars() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    boolean ret = false;
    for (Font font : fonts) {
        if (isLogicalFont(font) && font.canDisplayUpTo(phoneticExtnChars) == -1) {
            ret = true;
            break;
        }
    }
    return ret;
}
 
Example 13
Source File: PhoneticExtensionsGlyphTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static boolean canDisplayPhoneticChars() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    boolean ret = false;
    for (Font font : fonts) {
        if (isLogicalFont(font) && font.canDisplayUpTo(phoneticExtnChars) == -1) {
            ret = true;
            break;
        }
    }
    return ret;
}
 
Example 14
Source File: GAF.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String args[]) {
  GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  Font[] fonts = ge.getAllFonts();
  for (int i=0;i<fonts.length;i++) {
   System.out.println("Fam="+fonts[i].getFamily()+
         ", Full="+ fonts[i].getFontName()+
       ", ps="+ fonts[i].getPSName()+", "+fonts[i]);
  }
}
 
Example 15
Source File: GetAllFontTest.java    From oim-fx with MIT License 5 votes vote down vote up
public static void main(String[] args) {
	GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	Font[] fonts = ge.getAllFonts();
	for (Font font : fonts) {
		System.out.println(font.getFontName(Locale.ENGLISH));
		System.out.println(font.getFontName());
		System.out.println(font.getName());
	}
}
 
Example 16
Source File: FontHelper.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Determines the name of the monospace font of the system.
 * 
 * @return The name of the system monospace font.
 */
public static String getMonospaceFont() {
  final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
  final Font[] allfonts = env.getAllFonts();

  for (final Font font : allfonts) {
    if (font.getName().equals("Courier New")) {
      return "Courier New";
    }
  }

  return Font.MONOSPACED;
}
 
Example 17
Source File: PhoneticExtensionsGlyphTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static boolean canDisplayPhoneticChars() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = ge.getAllFonts();
    boolean ret = false;
    for (Font font : fonts) {
        if (isLogicalFont(font) && font.canDisplayUpTo(phoneticExtnChars) == -1) {
            ret = true;
            break;
        }
    }
    return ret;
}
 
Example 18
Source File: MaxAdvanceIsMax.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    GraphicsEnvironment e =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = e.getAllFonts();
    BufferedImage bi = new BufferedImage(500, 500,
            BufferedImage.TYPE_INT_RGB);
    for (AntialiasHint antialiasHint : antialiasHints) {
        for (Font f : fonts) {
            for (StyleAndSize styleAndSize : stylesAndSizes) {
                f = f.deriveFont(styleAndSize.style, styleAndSize.size);
                Graphics2D g2d = bi.createGraphics();
                g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                        antialiasHint.getHint());
                FontMetrics fm = g2d.getFontMetrics(f);
                int[] width;
                int maxWidth = -1;
                int maxAdvance = fm.getMaxAdvance();
                if (debug) {
                    System.out.println("Testing " + f + " in " +
                            antialiasHint);
                    System.out.println("getMaxAdvance: " + maxAdvance);
                }
                if (maxAdvance != -1) {
                    String failureMessage = null;
                    width = fm.getWidths();
                    for (int j = 0; j < width.length; j++) {
                        if (width[j] > maxWidth) {
                            maxWidth = width[j];
                        }
                        if (width[j] > maxAdvance) {
                            failureMessage = "FAILED: getMaxAdvance is " +
                                             "not max for font: " +
                                             f.toString() +
                                             " getMaxAdvance(): " +
                                             maxAdvance +
                                             " getWidths()[" + j + "]: " +
                                             width[j];
                            throw new Exception(failureMessage);
                        }
                    }
                }
                if (debug) {
                    System.out.println("Max char width: " + maxWidth);
                    System.out.println("PASSED");
                    System.out.println(".........................");
                }
            }
        }
    }
    System.out.println("TEST PASS - OK");
}
 
Example 19
Source File: MaxAdvanceIsMax.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    GraphicsEnvironment e =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = e.getAllFonts();
    BufferedImage bi = new BufferedImage(500, 500,
            BufferedImage.TYPE_INT_RGB);
    for (AntialiasHint antialiasHint : antialiasHints) {
        for (Font f : fonts) {
            for (StyleAndSize styleAndSize : stylesAndSizes) {
                f = f.deriveFont(styleAndSize.style, styleAndSize.size);
                Graphics2D g2d = bi.createGraphics();
                g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                        antialiasHint.getHint());
                FontMetrics fm = g2d.getFontMetrics(f);
                int[] width;
                int maxWidth = -1;
                int maxAdvance = fm.getMaxAdvance();
                if (debug) {
                    System.out.println("Testing " + f + " in " +
                            antialiasHint);
                    System.out.println("getMaxAdvance: " + maxAdvance);
                }
                if (maxAdvance != -1) {
                    String failureMessage = null;
                    width = fm.getWidths();
                    for (int j = 0; j < width.length; j++) {
                        if (width[j] > maxWidth) {
                            maxWidth = width[j];
                        }
                        if (width[j] > maxAdvance) {
                            failureMessage = "FAILED: getMaxAdvance is " +
                                             "not max for font: " +
                                             f.toString() +
                                             " getMaxAdvance(): " +
                                             maxAdvance +
                                             " getWidths()[" + j + "]: " +
                                             width[j];
                            throw new Exception(failureMessage);
                        }
                    }
                }
                if (debug) {
                    System.out.println("Max char width: " + maxWidth);
                    System.out.println("PASSED");
                    System.out.println(".........................");
                }
            }
        }
    }
    System.out.println("TEST PASS - OK");
}
 
Example 20
Source File: MaxAdvanceIsMax.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    GraphicsEnvironment e =
            GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fonts = e.getAllFonts();
    BufferedImage bi = new BufferedImage(500, 500,
            BufferedImage.TYPE_INT_RGB);
    for (AntialiasHint antialiasHint : antialiasHints) {
        for (Font f : fonts) {
            for (StyleAndSize styleAndSize : stylesAndSizes) {
                f = f.deriveFont(styleAndSize.style, styleAndSize.size);
                Graphics2D g2d = bi.createGraphics();
                g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                        antialiasHint.getHint());
                FontMetrics fm = g2d.getFontMetrics(f);
                int[] width;
                int maxWidth = -1;
                int maxAdvance = fm.getMaxAdvance();
                if (debug) {
                    System.out.println("Testing " + f + " in " +
                            antialiasHint);
                    System.out.println("getMaxAdvance: " + maxAdvance);
                }
                if (maxAdvance != -1) {
                    String failureMessage = null;
                    width = fm.getWidths();
                    for (int j = 0; j < width.length; j++) {
                        if (width[j] > maxWidth) {
                            maxWidth = width[j];
                        }
                        if (width[j] > maxAdvance) {
                            failureMessage = "FAILED: getMaxAdvance is " +
                                             "not max for font: " +
                                             f.toString() +
                                             " getMaxAdvance(): " +
                                             maxAdvance +
                                             " getWidths()[" + j + "]: " +
                                             width[j];
                            throw new Exception(failureMessage);
                        }
                    }
                }
                if (debug) {
                    System.out.println("Max char width: " + maxWidth);
                    System.out.println("PASSED");
                    System.out.println(".........................");
                }
            }
        }
    }
    System.out.println("TEST PASS - OK");
}