Example usage for java.awt Font canDisplay

List of usage examples for java.awt Font canDisplay

Introduction

In this page you can find the example usage for java.awt Font canDisplay.

Prototype

public boolean canDisplay(int codePoint) 

Source Link

Document

Checks if this Font has a glyph for the specified character.

Usage

From source file:Main.java

public static void main(String[] args) {
    final int w = 20;
    final int side = 25;
    final int[][] grid = new int[50][w];

    JPanel panel = new JPanel() {
        public void paintComponent(Graphics g) {
            Font font = new Font("WingDings", Font.PLAIN, 14);
            g.setFont(font);//w  w  w. j  a  v a  2s  .  co  m
            int off = 0;
            for (int i = 0; i < 256 * 256; i++) {
                if (font.canDisplay((char) i)) {
                    off++;
                    grid[off / w][off % w] = i;
                    int x = off % w * side;
                    int y = (off / w) * side + side;
                    g.drawString("" + (char) i, x, y);
                }
            }
        }
    };
    JFrame frame = new JFrame();
    panel.setSize(300, 300);
    frame.getContentPane().add(panel);
    frame.setSize(300, 300);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    final int columnCount = 10;
    final int side = 25;
    final int[][] grid = new int[50][columnCount];

    JPanel panel = new JPanel() {
        public void paintComponent(Graphics g) {
            Font font = new Font("WingDings", Font.PLAIN, 14);
            g.setFont(font);/*from  w w w .j av  a  2 s .  c om*/
            int off = 0;
            for (int i = 0; i < 256 * 256; i++) {
                if (font.canDisplay((char) i) == false) {
                    continue;
                }
                off++;
                grid[off / columnCount][off % columnCount] = i;
                int x = off % columnCount * side;
                int y = (off / columnCount) * side + side;
                g.drawString(Character.toString((char) i), x, y);

            }
        }
    };
    JFrame frame = new JFrame();
    panel.setSize(300, 300);
    frame.getContentPane().add(panel);
    frame.setSize(300, 300);
    frame.setVisible(true);
}

From source file:Main.java

public static String getFontPrintableChars(Font font) {
    StringBuilder result = new StringBuilder();
    for (int i = 0; i <= 255; i++) {
        if (font.canDisplay(i)) {
            result.append((char) i);
        }//  ww  w  .  j a  v  a 2  s . co  m
    }
    System.out.println(result);
    return result.toString();
}

From source file:components.ListDialogRunner.java

/**
 * Finds a cursive font to use, or falls back to using
 * an italic serif font./*www .  j a  v a  2  s. co  m*/
 */
protected static Font getAFont() {
    //initial strings of desired fonts
    String[] desiredFonts = { "French Script", "FrenchScript", "Script" };

    String[] existingFamilyNames = null; //installed fonts
    String fontName = null; //font we'll use

    //Search for all installed font families.  The first
    //call may take a while on some systems with hundreds of
    //installed fonts, so if possible execute it in idle time,
    //and certainly not in a place that delays painting of
    //the UI (for example, when bringing up a menu).
    //
    //In systems with malformed fonts, this code might cause
    //serious problems; use the latest JRE in this case. (You'll
    //see the same problems if you use Swing's HTML support or
    //anything else that searches for all fonts.)  If this call
    //causes problems for you under the latest JRE, please let
    //us know.
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    if (ge != null) {
        existingFamilyNames = ge.getAvailableFontFamilyNames();
    }

    //See if there's one we like.
    if ((existingFamilyNames != null) && (desiredFonts != null)) {
        int i = 0;
        while ((fontName == null) && (i < desiredFonts.length)) {

            //Look for a font whose name starts with desiredFonts[i].
            int j = 0;
            while ((fontName == null) && (j < existingFamilyNames.length)) {
                if (existingFamilyNames[j].startsWith(desiredFonts[i])) {

                    //We've found a match.  Test whether it can display 
                    //the Latin character 'A'.  (You might test for
                    //a different character if you're using a different
                    //language.)
                    Font f = new Font(existingFamilyNames[j], Font.PLAIN, 1);
                    if (f.canDisplay('A')) {
                        fontName = existingFamilyNames[j];
                        System.out.println("Using font: " + fontName);
                    }
                }

                j++; //Look at next existing font name.
            }
            i++; //Look for next desired font.
        }
    }

    //Return a valid Font.
    if (fontName != null) {
        return new Font(fontName, Font.PLAIN, 36);
    } else {
        return new Font("Serif", Font.ITALIC, 36);
    }
}

From source file:eulermind.Style.java

public static ArrayList<String> getFontFamilies() {
    ArrayList<String> fontFamilies = new ArrayList<String>();
    for (String family : GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()) {
        Font font = new Font(family, Font.PLAIN, 1);
        if (font.canDisplay('a')) {
            fontFamilies.add(family);//from  w  ww.  j  a  v a2 s.com
        }
    }

    return fontFamilies;
}

From source file:Main.java

public void paint(Graphics g) {
    int fontSize = 20;
    Font font = new Font("TimesRoman", Font.PLAIN, fontSize);
    g.setFont(font);//from   www . j  av a  2 s  .co  m

    font.canDisplay('A');

    String s = "www.java2s.com";

    g.setColor(Color.black);
    g.drawString(s, 30, 30);
}

From source file:com.github.benchdoos.weblocopener.updater.gui.UpdateDialog.java

/**
 * @noinspection ALL/*from w w  w.  jav a2  s  .c o m*/
 */
private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) {
    if (currentFont == null)
        return null;
    String resultName;
    if (fontName == null) {
        resultName = currentFont.getName();
    } else {
        Font testFont = new Font(fontName, Font.PLAIN, 10);
        if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
            resultName = fontName;
        } else {
            resultName = currentFont.getName();
        }
    }
    return new Font(resultName, style >= 0 ? style : currentFont.getStyle(),
            size >= 0 ? size : currentFont.getSize());
}